package com.jiexinyun;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.util.StatusPrinter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@Slf4j
@EnableScheduling
@SpringBootApplication
public class WebApplication implements CommandLineRunner {

    public static void main(String[] args) {
        // 注册 Shutdown Hook
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            log.error("服务即将退出，请检查原因！");
            // 可添加其他清理逻辑（如关闭数据库连接、释放资源等）
        }));
        SpringApplication.run(WebApplication.class, args);
    }

    @Override
    public void run(String... args) {
        // 打印Logback状态
        LoggerContext lc = (LoggerContext) org.slf4j.LoggerFactory.getILoggerFactory();
        log.info("Logback Status:");
        StatusPrinter.print(lc);
    }

}
